package org.example.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Demo04JDBC {
    public static void main(String[] args) throws Exception {
        try( Connection connection = DBUtil.getConnection()){
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery("SELECT username,password,age from user");
            //查询是返回一个集合 resultSet  resultSet.next()判读是否存在下一个元素 游标初始位置在第一个元素之前
            while(resultSet.next()){
                System.out.print(resultSet.getString("name"));
                System.out.print(",");
                System.out.print(resultSet.getString("password"));
                System.out.print(",");
                System.out.print(resultSet.getInt("age"));

            }
        }catch (SQLException e){
            System.out.println("SQLException");
        }
    }
}
